<html>
<head><meta charset="utf-8"><title>wasi linker unknown argument: --as-needed · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/wasi.20linker.20unknown.20argument.3A.20--as-needed.html">wasi linker unknown argument: --as-needed</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="240940433"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/wasi%20linker%20unknown%20argument%3A%20--as-needed/near/240940433" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Albert Cervin <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/wasi.20linker.20unknown.20argument.3A.20--as-needed.html#240940433">(Jun 01 2021 at 13:22)</a>:</h4>
<p>Seems like <a href="https://github.com/rust-lang/rust/commit/6615ee89be2290c96aa7d4ab24dc94e23a8c7080">this</a> commit added the flag <code>--as-needed</code> when linker flavor is GCC. However, using LLVM 12 linker to link a WASI binary on nightly, now fails with <code>wasm32-unknown-wasi-wasm-ld: error: unknown argument: --as-needed</code>. This is using <code>cc</code> from the wasi toolchain as linker. Any ideas what to do here?</p>



<a name="240960578"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/wasi%20linker%20unknown%20argument%3A%20--as-needed/near/240960578" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/wasi.20linker.20unknown.20argument.3A.20--as-needed.html#240960578">(Jun 01 2021 at 15:36)</a>:</h4>
<p>The fix is to add <code>linker_is_gnu: false</code> to <a href="https://github.com/rust-lang/rust/blob/master/compiler/rustc_target/src/spec/wasm_base.rs">https://github.com/rust-lang/rust/blob/master/compiler/rustc_target/src/spec/wasm_base.rs</a> because wasm linker is not gnu.</p>



<a name="240960878"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/wasi%20linker%20unknown%20argument%3A%20--as-needed/near/240960878" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/wasi.20linker.20unknown.20argument.3A.20--as-needed.html#240960878">(Jun 01 2021 at 15:38)</a>:</h4>
<p>(It still supports <code>--gc-sections</code> so the fix will also require adding <code>self.sess.target.is_like_wasm</code> cases to <a href="https://github.com/rust-lang/rust/blob/master/compiler/rustc_codegen_ssa/src/back/linker.rs#L452-L486">https://github.com/rust-lang/rust/blob/master/compiler/rustc_codegen_ssa/src/back/linker.rs#L452-L486</a>)</p>



<a name="240960886"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/wasi%20linker%20unknown%20argument%3A%20--as-needed/near/240960886" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/wasi.20linker.20unknown.20argument.3A.20--as-needed.html#240960886">(Jun 01 2021 at 15:38)</a>:</h4>
<p>cc <span class="user-mention" data-user-id="132778">@Luqman Aden</span></p>



<a name="241075540"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/wasi%20linker%20unknown%20argument%3A%20--as-needed/near/241075540" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Albert Cervin <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/wasi.20linker.20unknown.20argument.3A.20--as-needed.html#241075540">(Jun 01 2021 at 21:05)</a>:</h4>
<p>Wow, thanks for the insight, I have worked around it with a wrapper script in the meantime <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span></p>



<a name="241088911"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/wasi%20linker%20unknown%20argument%3A%20--as-needed/near/241088911" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luqman Aden <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/wasi.20linker.20unknown.20argument.3A.20--as-needed.html#241088911">(Jun 01 2021 at 23:34)</a>:</h4>
<p>Ah, good catch! If possible could you also try passing <code>-C linker-flavor=wasm-ld</code> in RUSTFLAGS or something? I think the linker flavor infer <a href="https://github.com/rust-lang/rust/blob/f64503eb555475d65ae5503ef22439ca5dd394fd/compiler/rustc_codegen_ssa/src/back/link.rs#L957-L1040">logic</a> is classifying linker flavour as LD due to the linker cmd ending in <code>-ld</code>.</p>
<p>And out of curiousity, is there any reason you use <code>wasm32-unknown-wasi-wasm-ld</code> instead of <code>rust-lld</code>?</p>



<a name="241092315"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/wasi%20linker%20unknown%20argument%3A%20--as-needed/near/241092315" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luqman Aden <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/wasi.20linker.20unknown.20argument.3A.20--as-needed.html#241092315">(Jun 02 2021 at 00:26)</a>:</h4>
<p>Created a PR to address this: <a href="https://github.com/rust-lang/rust/pull/85920">https://github.com/rust-lang/rust/pull/85920</a></p>



<a name="241112107"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/wasi%20linker%20unknown%20argument%3A%20--as-needed/near/241112107" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Albert Cervin <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/wasi.20linker.20unknown.20argument.3A.20--as-needed.html#241112107">(Jun 02 2021 at 07:02)</a>:</h4>
<p>I use a custom libc, that is why and that is also why I need to use the compiler (cc) instead of the linker directly</p>



<a name="241112158"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/wasi%20linker%20unknown%20argument%3A%20--as-needed/near/241112158" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Albert Cervin <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/wasi.20linker.20unknown.20argument.3A.20--as-needed.html#241112158">(Jun 02 2021 at 07:03)</a>:</h4>
<p>Since the nix wrapper for the wasi target does not expose <code>wasm-ld</code> directly, only through <code>clang</code></p>



<a name="241113520"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/wasi%20linker%20unknown%20argument%3A%20--as-needed/near/241113520" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Albert Cervin <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/wasi.20linker.20unknown.20argument.3A.20--as-needed.html#241113520">(Jun 02 2021 at 07:22)</a>:</h4>
<p>And we actually have to set <code>linker-flavor </code>to <code>gcc</code> for it to work</p>



<a name="241120029"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/wasi%20linker%20unknown%20argument%3A%20--as-needed/near/241120029" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Albert Cervin <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/wasi.20linker.20unknown.20argument.3A.20--as-needed.html#241120029">(Jun 02 2021 at 08:37)</a>:</h4>
<p>Otherwise I _think_ it detects it as <code>wasm-ld</code> and starts sending flags that <code>clang</code> does not understand</p>



<a name="241179338"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/wasi%20linker%20unknown%20argument%3A%20--as-needed/near/241179338" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luqman Aden <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/wasi.20linker.20unknown.20argument.3A.20--as-needed.html#241179338">(Jun 02 2021 at 17:10)</a>:</h4>
<p>Ah, got it. Thanks!</p>



<a name="241704746"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/wasi%20linker%20unknown%20argument%3A%20--as-needed/near/241704746" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luqman Aden <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/wasi.20linker.20unknown.20argument.3A.20--as-needed.html#241704746">(Jun 06 2021 at 18:41)</a>:</h4>
<p>Merged, should be in the next nightly. Thanks!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>